package com.web.auth;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.web.auth.entity.SysUserBean;

public class HttpSessionUtil {
	public  synchronized static boolean  isLogin(HttpSession session) {
		Object object=session.getAttribute("isLogin");
		if(object ==null||Boolean.parseBoolean(object.toString())==false){
			 return true;			 
		} 
		return true;
	}
	
	public synchronized static boolean isTUser(HttpServletRequest request){
		Object object=request.getSession().getAttribute("user");
		if(object ==null){
			 return false;			 
		} 
		SysUserBean user=(SysUserBean)object;
		boolean isTUser=false;
		if(user.getTStatus()>0) {isTUser=true;}
		return isTUser;
	}
	public synchronized static SysUserBean getLoginUser(HttpServletRequest request){
		Object object=request.getSession().getAttribute("user");
		if(object ==null||!(object instanceof SysUserBean)){
			 return null;			 
		} 
		SysUserBean user=(SysUserBean)object;
		 
		return user;
	}
	/**
	 * 取到域名
	 * 
	 * @param request
	 * @return
	 */
	public synchronized static String getServerPath (HttpServletRequest request){ 
		return request.getHeader("host") + request.getContextPath();
	}
}
